<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OpenShoe: genclk.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenShoe
   &#160;<span id="projectnumber">0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">genclk.h</div>  </div>
</div>
<div class="contents">
<a href="uc3c_2genclk_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef CHIP_GENCLK_H_INCLUDED</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define CHIP_GENCLK_H_INCLUDED</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="group__genclk__group.html#gada51baf0de37e57d7052f6f6ea324b53">00049</a> <span class="preprocessor">#define GENCLK_DIV_MAX  256</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="preprocessor">#ifndef __ASSEMBLY__</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;avr32/io.h&gt;</span>
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="group__genclk__group.html#gaca55f4f4f96549b8111139d144bce01c">00056</a> <span class="keyword">enum</span> <a class="code" href="group__genclk__group.html#gaca55f4f4f96549b8111139d144bce01c" title="Generic clock source ID.">genclk_source</a> {
<a name="l00057"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca953707a1c76a0268413b7232d99d0065">00057</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca953707a1c76a0268413b7232d99d0065" title="System RC oscillator.">GENCLK_SRC_RCSYS</a>        = 0,    
<a name="l00058"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca3d1fd9213fb1acca868f9aed0580080f">00058</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca3d1fd9213fb1acca868f9aed0580080f" title="32 kHz oscillator">GENCLK_SRC_OSC32K</a>       = 1,    
<a name="l00059"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01caeb9bb887118c6aaf7a1c193f80205909">00059</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01caeb9bb887118c6aaf7a1c193f80205909" title="8 MHz RC oscillator">GENCLK_SRC_RC8M</a>         = 2,    
<a name="l00060"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca885a673e1f2c68e84f6461cb38d2e50f">00060</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca885a673e1f2c68e84f6461cb38d2e50f" title="Oscillator 0.">GENCLK_SRC_OSC0</a>         = 3,    
<a name="l00061"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca2c0a57ce35b0fa7efac9930357278930">00061</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca2c0a57ce35b0fa7efac9930357278930" title="Oscillator 1.">GENCLK_SRC_OSC1</a>         = 4,    
<a name="l00062"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca4db9dbbdde9e4efb5b26e8ddfe817812">00062</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca4db9dbbdde9e4efb5b26e8ddfe817812" title="PLL 0.">GENCLK_SRC_PLL0</a>         = 5,    
<a name="l00063"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca229fcad1bdb8ec267a05a8f1d1b0491e">00063</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca229fcad1bdb8ec267a05a8f1d1b0491e" title="PLL 1.">GENCLK_SRC_PLL1</a>         = 6,    
<a name="l00064"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01cac903dd8fc4bf4fbdfa810ab774035a1b">00064</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01cac903dd8fc4bf4fbdfa810ab774035a1b" title="CPU clock.">GENCLK_SRC_CLK_CPU</a>      = 7,    
<a name="l00065"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca5bb1dbdcf7db89069ddcc2a59d36a6b6">00065</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca5bb1dbdcf7db89069ddcc2a59d36a6b6" title="High Speed Bus clock.">GENCLK_SRC_CLK_HSB</a>      = 8,    
<a name="l00066"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca0647cd0e7fc56115d0003306568c29ff">00066</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca0647cd0e7fc56115d0003306568c29ff" title="Peripheral Bus A clock.">GENCLK_SRC_CLK_PBA</a>      = 9,    
<a name="l00067"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca956d2618a06550aba0d3c2c1cd784be9">00067</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca956d2618a06550aba0d3c2c1cd784be9" title="Peripheral Bus B clock.">GENCLK_SRC_CLK_PBB</a>      = 10,   
<a name="l00068"></a><a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca73e71d3958e85af71ec37d4e2ca76c54">00068</a>         <a class="code" href="group__genclk__group.html#ggaca55f4f4f96549b8111139d144bce01ca73e71d3958e85af71ec37d4e2ca76c54" title="Peripheral Bus C clock.">GENCLK_SRC_CLK_PBC</a>      = 11,   
<a name="l00069"></a>00069 };
<a name="l00070"></a>00070 
<a name="l00072"></a>00072 
<a name="l00073"></a><a class="code" href="structgenclk__config.html">00073</a> <span class="keyword">struct </span><a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> {
<a name="l00074"></a><a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">00074</a>         uint32_t <a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a>;
<a name="l00075"></a>00075 };
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_config_defaults(<span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00078"></a>00078                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080         cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> = 0;
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_config_read(<span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00084"></a>00084                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086         cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> = AVR32_SCIF.gcctrl[id];
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_config_write(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00090"></a>00090                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092         AVR32_SCIF.gcctrl[id] = cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a>;
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_config_set_source(<span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00096"></a>00096                 <span class="keyword">enum</span> <a class="code" href="group__genclk__group.html#gaca55f4f4f96549b8111139d144bce01c" title="Generic clock source ID.">genclk_source</a> src)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098         cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> = (cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> &amp; ~AVR32_SCIF_GCCTRL_OSCSEL_MASK)
<a name="l00099"></a>00099                         | (src &lt;&lt; AVR32_SCIF_GCCTRL_OSCSEL);
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_config_set_divider(<span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00103"></a>00103                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> divider)
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105         Assert(divider &gt; 0 &amp;&amp; divider &lt;= <a class="code" href="group__genclk__group.html#gada51baf0de37e57d7052f6f6ea324b53" title="Maximum divider supported by the generic clock implementation.">GENCLK_DIV_MAX</a>);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         <span class="comment">/* Clear all the bits we&#39;re about to modify */</span>
<a name="l00108"></a>00108         cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> &amp;= ~(AVR32_SCIF_GCCTRL_DIVEN_MASK
<a name="l00109"></a>00109                         | AVR32_SCIF_GCCTRL_DIV_MASK);
<a name="l00110"></a>00110 
<a name="l00111"></a>00111         <span class="keywordflow">if</span> (divider &gt; 1) {
<a name="l00112"></a>00112                 cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> |= 1U &lt;&lt; AVR32_SCIF_GCCTRL_DIVEN;
<a name="l00113"></a>00113                 cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> |= (((divider + 1) / 2) - 1) &lt;&lt; AVR32_SCIF_GCCTRL_DIV;
<a name="l00114"></a>00114         }
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_enable(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structgenclk__config.html" title="Hardware representation of a set of generic clock parameters.">genclk_config</a> *cfg,
<a name="l00118"></a>00118                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120         AVR32_SCIF.gcctrl[id] = cfg-&gt;<a class="code" href="structgenclk__config.html#a627f2d3129c376569dd181a3f69db17b">ctrl</a> | (1U &lt;&lt; AVR32_SCIF_GCCTRL_CEN);
<a name="l00121"></a>00121 }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> genclk_disable(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125         AVR32_SCIF.gcctrl[id] = 0;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 <span class="preprocessor">#endif </span><span class="comment">/* __ASSEMBLY__ */</span>
<a name="l00129"></a>00129 
<a name="l00131"></a>00131 
<a name="l00132"></a>00132 <span class="preprocessor">#endif </span><span class="comment">/* CHIP_GENCLK_H_INCLUDED */</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Mon Dec 19 2011 21:04:51 for OpenShoe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
